﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataBaseLayer;

namespace MySQLDB.Business
{
    public class ChatBussiness
    {
        /// <summary>
        /// 做5次的Cache
        /// </summary>
        /// <param name="dv"></param>
        public static void InserOrUpdate(devicechat dv)
        {
            using (Db aa = Demo.DbInit())
            {
                aa.DeviceChat.InsertOrUpdate(dv);
            }
        }

        public static string GetTop5ChatMessage(string uuid)
        {
            using (Db aa = Demo.DbInit())
            {
                StringBuilder sb = new StringBuilder();
                var a3 = aa.Query<devicechat>("select * from devicechat where uuid=@uuid order by datetime", new { uuid = uuid });
                foreach (var item in a3)
                {
                    sb.AppendFormat("{0} {1}:{2}", item.DateTime, item.UUID, item.chatMsg);
                }
                return sb.ToString();
            }
        }
    }
}
